var type='';
var content='';
var labelid='';
var faultphoto = [];//拍照列表
$(document).ready(function(){
	console.log(userId);
	getlabel(userId);
	getpingjia();
	
	$("#searchtext").on("input",function(){
	$('#pinglun_main').html("");
	if($("#searchtext").val() == ""){
		content ="";
		getpingjia();
	}else{
		content = $("#searchtext").val()
		getpingjia();
	}
	})

});	
function getlabel(){
	$.ajax({  
		url: "../../unite_platform/mobile_pingjia/get_label"
		,type:'post'
		,async: false
		,contentType: "application/json; charset=utf-8"
		,data:JSON.stringify({"userId":userId}) 
		,dataType:'json'
		,success: function(res){
			for(var i=0;i<4;i++){
				if(res.data[i] != undefined && res.data[i].label_name != undefined){
				$('#label').append(
					'<div class="add_inlblo flo_left h26p add_mar_r2 bg_skin_light add_rad_15p fs_12p add_pad_lr3 add_mar_t2 orange" onclick="label('+res.data[i].label+')">'+res.data[i].label_name+'('+res.data[i].Lsum+')</div>'
				)
				}
			}
			$('#label').append('<div class="clearfix"></div>');
		}
	});
}
function label(id){
	labelid=id;
	getpingjia();
}
function change(type1){
	var classnameA='add_inlblo blue add_bor_b_blue3';
	var classnameB='add_inlblo gray_dark add_bor_b_white3';
	$('#all')[0].className=classnameB;
	$('#positive')[0].className=classnameB;
	$('#negative')[0].className=classnameB;
	$('#'+type1)[0].className=classnameA;
	type =type1;
	getpingjia();
}
function getpingjia(){
	$.ajax({  
		url: "../../unite_platform/mobile_pingjia/getpingjia"
		,type:'post'
		,async: false
		,contentType: "application/json; charset=utf-8"
		,data:JSON.stringify({'userId':userId,'type':type,'content':content,'labelid':labelid}) 
		,dataType:'json'
		,success: function(res){
			console.log(res);
			$('#pinglun_main').html('');
			for(var i=0;i<res.data.length;i++){
				var photohtml="";
				if(res.data[i].photo=='' || res.data[i].photo==undefined || res.data[i].anonymous =='0'){
					photohtml='../../unite_platform/genius/style/mobile_page/assets/images/jh_logo.png';
				}else{
					photohtml=res.data[i].photo;
				}
				$('#pinglun_main').append(
					'<div class="w94 add_pad3 add_bor_b_gray" id="pinglun'+i+'"></div>'
				)
				$('#pinglun'+i).append(
					'<div class="w100 add_pad_tb3 fle_content_row fle_just_start fle_alig_center">'
					+'<div class="w35p h35p add_mar_r2">'
					+'<img class="w100 h100 add_rad_half" src="'+photohtml+'" /></div> '
					+'<div class="fle_gro_1 w0 fle_content_col fle_just_aro">'	
					+'<div class="add_inlblo add_mar_r2 fs_14p add_weight gray_dark">'+(res.data[i].anonymous=='0'?'匿名用户':res.data[i].lrr)+'<i class="iconfont orange">&#xe6c2;</i></div>'
					+'<div class="w100 add_mar_t5p fle_content_row fle_just_start fle_alig_center">'
					+'<div class="add_inlblo fs_12p add_scale_8 add_origin_left"><div id="star'+i+'"></div></div><span style="margin-left:-5%;">|</span>'
					+'<div class="add_inlblo add_mar_l2 fs_12p gray">'+res.data[i].lrsj+'发表</div>'
					+'</div></div></div>'
					+'<div class="w100 fs_14p">'+res.data[i].content+'</div>'
				)
				if(res.data[i].pic != "" && res.data[i].pic != undefined){
					faultphoto =[res.data[i].pic]
					var m = res.data[i].pic.split(",");
					if(m.length>0){
						$('#pinglun'+i).append('<div class="w100 h80p add_mar_t3 " id="picdiv'+i+'"></div>');
						for(var s=0;s<m.length;s++){
							$('#picdiv'+i).append(
								'<div class="w80p h80p add_inlblo flo_left add_mar_r2"><img class="w100 h100" src="'+m[s]+'"  onclick="showAllPic(\''+m[s]+'\')"/></div>'
							)
						}
					}
				}
				layui.use(['rate'], function(){
				  var rate = layui.rate;
					  rate.render({
					    elem: '#star'+i 
				 		,text: false
						,readonly: true
						,value:res.data[i].star
					 })
				});
			}
		}
	});
}
//预览图片
function showAllPic(imgOne){
	dd.biz.util.previewImage({
		urls: faultphoto,//图片地址列表
		current: imgOne,//当前显示的图片链接
		onSuccess : function(result) {
			/**/
		},
		onFail : function(err) {}
	})
}	